// 封装高阶组件
// 核心逻辑：有 token 正常跳转；无 token 跳转至登录页
import { Navigate } from "react-router-dom";

// children 是真正要跳转的组件
function AuthRoute({ children }) {
  const token = localStorage.getItem("token");
  if (!token) {
    return <Navigate to="/login" replace />;
  } else {
    return <>{children}</>;
  }
}

export default AuthRoute;
